import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

public class Demo2 {
    public static void main(String[] args) {

        BlockingQueue<Integer> queue=new LinkedBlockingDeque(100000);

        Thread product=new Thread(()->{
            int n=0;
            while (true){
                try {
                    queue.put(n);
                    System.out.println("生产元素"+n);
                    n++;

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"生产者");

        Thread consume=new Thread(()->{
            while(true){
                try {
                    Integer n=queue.take();
                    System.out.println("消费元素"+n);
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();

                }
            }
        });

        product.start();
        consume.start();
    }
}
